package define

type ResCode int64

// 成功响应状态码
const (
	CodeSuccess ResCode = 200

	CodeSuccessLogin ResCode = 1100 + iota
	CodeSuccessGetMenus
	CodeSuccessChangePwd
	CodeSuccessAddMenu
	CodeSuccessDelMenu
	CodeSuccessUpdateMenu
	CodeSuccessGetRoles
	CodeSuccessCreateRole
	CodeSuccessDelRole
	CodeSuccessGetRoleDetail
	CodeSuccessUpdateRole
	CodeSuccessUpdate
	CodeSuccessGetUserList
	CodeSuccessDelUser
	CodeSuccessCreateUser
	CodeSuccessUpdateUser
	CodeSuccessGetUserDetail
	CodeSuccessUpdateAvatar
)

// 错误响应状态码
const (
	CodeError404     ResCode = 404
	CodeInvalidToken ResCode = 1234

	CodeInvalidParam ResCode = 1000 + iota
	CodeInvalidPassword
	CodeServerBusy

	CodeInvalidAuthFormat
	CodeNotLogin
	CodeRefreshTokenFailed
	CodeRoleError
	CodeDataError
	CodeOPasswordError
	CodeRequestError
	CodeRoleWithUser
	CodeUsernameExist
	CodePasswordIsNull
	CodeRoleNameExist
)

// 状态码名称
var codeMsgMap = map[ResCode]string{
	CodeInvalidParam:       "请求参数错误",
	CodeInvalidPassword:    "用户名或密码错误",
	CodeServerBusy:         "服务繁忙",
	CodeInvalidToken:       "无效的Token",
	CodeInvalidAuthFormat:  "认证格式有误",
	CodeNotLogin:           "用户未登录",
	CodeRefreshTokenFailed: "刷新Token失败",
	CodeRoleError:          "非法用户",
	CodeDataError:          "数据异常",
	CodeOPasswordError:     "旧密码填写错误",
	CodeRequestError:       "非法访问",
	CodeRoleWithUser:       "当前角色还存在用户",
	CodeError404:           "404：页面不存在",
	CodeUsernameExist:      "用户名已存在",
	CodeRoleNameExist:      "角色名已存在",
	CodePasswordIsNull:     "密码不能为空",

	CodeSuccess:              "success",
	CodeSuccessLogin:         "登录成功",
	CodeSuccessUpdate:        "更新成功",
	CodeSuccessGetMenus:      "菜单获取成功",
	CodeSuccessChangePwd:     "密码修改成功",
	CodeSuccessAddMenu:       "菜单新增成功",
	CodeSuccessDelMenu:       "菜单删除成功",
	CodeSuccessUpdateMenu:    "菜单更新成功",
	CodeSuccessGetRoles:      "角色获取成功",
	CodeSuccessCreateRole:    "角色创建成功",
	CodeSuccessDelRole:       "角色删除成功",
	CodeSuccessUpdateRole:    "角色更新成功",
	CodeSuccessDelUser:       "用户删除成功",
	CodeSuccessCreateUser:    "用户创建成功",
	CodeSuccessUpdateUser:    "用户更新成功",
	CodeSuccessGetRoleDetail: "角色详情获取成功",
	CodeSuccessGetUserList:   "用户列表获取成功",
	CodeSuccessGetUserDetail: "用户详情获取成功",
	CodeSuccessUpdateAvatar:  "头像更新成功",
}

func (rc ResCode) Msg() string {
	msg, ok := codeMsgMap[rc]
	if !ok {
		return codeMsgMap[CodeServerBusy]
	}
	return msg
}
